﻿using Bear.Library.WinApi;
using Bear.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bear.MapleStory
{
    public class MapleStory
    {

        public const int _TOP = 86;
        public const int _LEFT = 12;

        public static Size GetWindowSize()
        {
            return new Size(1024, 705);
        }



        public static Size GetWindowCenter()
        {
            return new Size(512, 450);
        }

        public static Size GetMonsterSize()
        {
            return new Size(300, 150);
        }


        public static Map GetMapDetail(string mapName)
        {
            Map map = null;
            switch (mapName)
            {
                case "死灵王":
                    map = new Map()
                    {
                        Width = 155,
                        Height = 167,
                        Left = 12,
                        Top = 86,
                    
                    };
                    break;
                case "死灵":
                    map = new Map()
                    {
                        Width = 171,
                        Height = 145,
                        Left = 12,
                        Top = 86,
                    
                    };
                    break;
                case "普通":
                    map = new Map()
                    {
                        Width = 171,
                        Height = 145,
                        Left = 12,
                        Top = 86
                    };
                    break;
                case "测试":
                    map = new Map()
                    {
                        Width = 155,
                        Height = 167,
                        Left = 12 + 5,
                        Top = 86 + 35,
                   
                    };
                    break;
                default:
                    break;
            }

            return map;
        }

        public static LifeAndMagic GetLifeBar()
        {
            return new LifeAndMagic()
            {
                Height = 12,
                Width = 139,
                Left = 3 + 251,//+ 5,
                Top = 25 + 736 //+ 35,
            };
        }

        public static LifeAndMagic GetMagicBar()
        {
            return new LifeAndMagic()
            {
                Height = 12,
                Width = 139,
                Left = 3 + 422,//+ 5,
                Top = 25 + 736 //+ 35,
            };
        }

        public static IntPtr FindWindow()
        {
            DataCenter dc = DataCenter.Load();

            IntPtr handle = WinApiHelper.FindWindow(null, "MapleStory");

            //测试
            if (handle == IntPtr.Zero)
            {
                handle = WinApiHelper.FindWindow(null, "Maple0005.jpg - Windows 照片查看器");
                dc.CurrentMap = MapleStory.GetMapDetail("测试");
                if (dc.Players == null || dc.Players.Count <= 0)
                {
                    dc.CurrentPlayer = new Player();
                    dc.CurrentPlayer.Life = GetLifeBar();
                    dc.CurrentPlayer.Magic = GetMagicBar();
                }
                else
                {
                    dc.CurrentPlayer = dc.Players[0];
                }

                dc.CurrentPlayer.Life.Top += 35;
                dc.CurrentPlayer.Life.Left += 5;

                dc.CurrentPlayer.Magic.Top += 35;
                dc.CurrentPlayer.Magic.Left += 5;
            }

            return handle;

        }

    }
}
